<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/icon/favicon.ico">
    <link rel="Shortcut Icon" href="/icon/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->

    <title>添加用户 - H-ui.admin v3.1</title>
</head>

<body>
    <article class="page-container">
        <form action="./member/add" method="POST" class="form form-horizontal" id="form-member-add">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="username" name="username">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>真实姓名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" autocomplete="off" value="" placeholder="" id="realname" name="realname">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>身份证：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" autocomplete="off" placeholder="" id="idcode" name="idcode">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="phone" name="phone">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>角色：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box">
                        <select class="select" name="role" id="role">
                            <option value="1">行业用户</option>
                            <option value="2">配送员</option>
                            <option value="3">药房(配药员)</option>
                            <option value="4">药房(审核)</option>
                        </select>
                    </span>
                </div>
            </div>
            <div class="row cl" id="selectSupplier">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>所在分组：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" value="" hidden class="input-text" id="supplierId" name="supplierId" >
                    <input type="text" onclick="chooseSupplier()" readonly class="input-text" value="" placeholder="请点击选择按钮选择分组,配送员无需选择分组"
                        id="supplierName" name="supplierName" style="width:50%">

                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input id="saveButton" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
    <style>
        .el-tag{
            background-color: rgba(64,158,255,.1);
            display: inline-block;
            padding: 0 10px;
            height: 32px;
            line-height: 30px;
            font-size: 12px;
            color: #409eff;
            border-radius: 4px;
            box-sizing: border-box;
            border: 1px solid rgba(64,158,255,.2);
            white-space: nowrap;
            margin-right: 5px;
        }
        .el-icon-close{
            border-radius: 50%;
            text-align: center;
            position: relative;
            cursor: pointer;
            font-size: 12px;
            height: 16px;
            width: 16px;
            line-height: 16px;
            vertical-align: middle;
            top: -1px;
            right: -5px;
            color: #409eff;
        }
    </style>

    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer 作为公共模版分离出去-->

    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>

    <script type="text/javascript">

        $('#role').on('change',function(){
            if($(this).val() !=="1"){
                $("#selectSupplier").hide()
            }else{
                $("#selectSupplier").show()
            }
        });


        //手机号码验证  
        jQuery.validator.addMethod("mobile", function (value, element) {
            var length = value.length;
            var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(19[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
            return this.optional(element) || (length == 11 && mobile.test(value));
        }, "请正确填写手机号码");


        $("#form-member-add").validate({
            rules: {
                username: {
                    required: true,
                    minlength: 2,
                    maxlength: 16,
                },
                phone: {
                    required: true,
                    mobile: true,
                },
                realname: {
                    required: true,
                },
                role: {
                    required: true
                }
            },
            onkeyup: false,
            focusCleanup: false,
            success: "valid",
            submitHandler: function (form) {
                var index = layer.load(3);
                getIds()
                $(form).ajaxSubmit({
                    success: function (data) {
                        layer.closeAll();
                        if (data.success === true) {
                            if (parent.location.pathname !== '/') {
                                parent.refresh();
                                parent.msgSuccess("添加成功!");
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            } else {
                                layer.confirm('添加成功!', {
                                    btn: ['确认'], icon: 1
                                }, function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                });
                            }
                        } else {
                            layer.close(index);
                            layer.alert('添加失败! ' + data.message, { title: '错误信息', icon: 2 });
                        }
                    },
                    error: function (XMLHttpRequest) {
                        layer.close(index);
                        layer.alert('数据处理失败! 错误码:' + XMLHttpRequest.status + ' 错误信息:' + JSON.parse(XMLHttpRequest.responseText).message, { title: '错误信息', icon: 2 });
                    }
                });
            }
        });

        function chooseSupplier() {
            layer_show("选择分组", "choose-supplier", 900, 600)
        }

        function setTidAndTname(id, name) {
            var ids = getIds()
            if (ids != ""){
                var idArray = ids.split(",")
                for (var j=0;j<idArray.length;j++){
                    if (id==idArray[j]){
                        return
                    }
                }
            }

            //添加元素
            $('#supplierId').before('<span data-sid="'+id+'" class="el-tag">'+name+'<i  class="Hui-iconfont el-icon-close">&#xe6a6</i></span>')

            // 添加元素后重新绑定删除元素事件
            $('[class=el-tag]').each(function (i,element) {
                $(element).find("i").unbind()
                $(element).find("i").click(function () {
                    $(element).remove()
                })
            })
        }


        function getIds() {
            var ids = ""
            $('[class=el-tag]').each(function (i,element) {
                var sid = $(element).data("sid")
                if (i === 0){
                    ids = sid.toString()
                } else {
                    ids = ids+","+sid
                }
            })
            $('#supplierId').val(ids)
            return ids;
        }

    </script>
    <!--/请在上方写此页面业务相关的脚本-->
</body>

</html>